<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form id="userForm" method="post" onsubmit="return false;">
<div class="layui-form layuimini-form" lay-filter="add_ncc">
    <div class="layui-form-item">
        <label class="layui-form-label required">自愈项</label>
        <div class="layui-input-block">
            <input type="text" name="item" id="item" lay-verify="required" lay-reqtext="自愈项名称不能为空" placeholder="请输入自愈项名称" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">告警类型</label>
        <div class="layui-input-block">
            <input type="text" name="type" id="type" lay-verify="required" lay-reqtext="告警类型不能为空" placeholder="请输入告警类型" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">告警级别</label>
        <div class="layui-input-block">
            <input type="text" name="level" id="level" lay-verify="required" lay-reqtext="告警级别不能为空" placeholder="请输入告警级别" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">告警端口</label>
        <div class="layui-input-block">
            <input type="text" name="port" id="port" lay-verify="required" lay-reqtext="告警端口不能为空" placeholder="请输入告警端口" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">自愈动作</label>
        <div class="layui-input-block">
            <input type="text" name="action" id="action" lay-verify="required" lay-reqtext="自愈动作不能为空" placeholder="请输入自愈动作" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">自愈开关</label>
        <div class="layui-input-block">
            <input type="checkbox" name="switch" lay-verify="required" checked  lay-text="开|关" lay-skin="switch" lay-filter="switchTest" title="开关">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">自愈状态</label>
        <div class="layui-input-block">
            <input type="text" name="status" id="status" lay-verify="required" lay-reqtext="自愈状态" placeholder="自愈状态" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label"></label>
       <button class="layui-btn" lay-filter="AddAutoPrometheus" type="submit" lay-submit >立即提交</button>
    </div>

</div>
</form>

<script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate'],function () {
        window.form = layui.form
            ,window.$ = layui.$
            , laydate = layui.laydate;

        form.render();

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            this.checked?data.value='on':data.value='off';
            layer.msg('开关checked：' + (this.checked ? 'on' : 'off'), {
                offset: '6px'
            });
            //layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(AddAutoPrometheus)', function (data) {
            //发异步，把数据提交给php
            var item = data.field.item;
            var type = data.field.type;
            var level = data.field.level;
            var port = data.field.port;
            var action = data.field.action;
            var swt = data.field.switch;
            var status = data.field.status;
            //alert(JSON.stringify(data));

            $.ajax({
                type: 'post',
                url: "/devops/prometheus/",
                data: {item: item,type:type,level: level,port:port,action: action,switch:swt,status:status},
                success: function (res) {
                    if (res.status == 0) {
                        layer.alert(res.msg, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                           //刷新页面
                            parent.location.reload();
                        });
                         //parent.layer.reload();

                    } else {
                        layer.alert(res.msg, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新页面
                            parent.location.reload();
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>